using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.CommonWeb;
using NTTHAO.Web.BL.Contact;

public partial class admin_webparts_Plug_ins_Contact_ContactGroupInput : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSave.Value = btnSave2.Value = LanguageUtility.GetLanguageText("SAVE", Session);
        chkActive.Text = LanguageUtility.GetLanguageText("ACTIVE", Session);

        try
        {
            if (!IsPostBack && Request.QueryString["id"] != null)
            {
                int contactGroupID = Convert.ToInt32(Request.QueryString["id"]);
                ContactGroup group = new ContactGroup(contactGroupID);
                if (group.ID < 1)
                {
                    throw new Exception();
                }

                txtName.Text = group.Name;
                chkActive.Checked = group.Actived;
            }
        }
        catch
        {
            string redirectURL = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"];
            Response.Redirect(redirectURL, false);
            return;
        }
    }

    public void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            ContactGroup group = null;
            if (Request.QueryString["id"] != null)
            {
                int catID = Convert.ToInt32(Request.QueryString["id"]);
                group = new ContactGroup(catID);
            }
            else
            {
                group = new ContactGroup();
                group.SiteID = WebGlobal.GetSite().ID;
                group.LanguageID = LanguageUtility.GetLanguageID();
            }
            group.Name = txtName.Text.Trim();
            group.Actived = chkActive.Checked;

            if (Request.QueryString["id"] != null)
            {
                group.Update();
            }
            else
            {
                group.Insert();
            }
        }
        catch { }

        string redirectURL = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"];
        Response.Redirect(redirectURL, false);
        return;
    }
}
